//
//  UILabel+HTFloat.m
//  CBPic2ker
//
//  Created by shuai pan on 2017/11/21.
//  Copyright © 2017年 cbangchen. All rights reserved.
//

#import "UILabel+HTFloat.h"

@implementation UILabel (HTFloat)
- (void)heightToFit:(NSString *)text fontSize:(CGFloat)font{
    CGFloat max_height = CGRectGetHeight([UIScreen mainScreen].bounds);
    CGRect rect = [text boundingRectWithSize:CGSizeMake(CGRectGetWidth(self.bounds)-10, max_height) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:font]} context:nil];
    CGRect self_rect = self.bounds;
    self_rect.size.height = rect.size.height;
    self.bounds = self_rect;
    self.adjustsFontSizeToFitWidth = YES;

}
- (void)widthToFit:(NSString *)text fontSize:(CGFloat)font{
    CGFloat max_width = CGRectGetWidth([UIScreen mainScreen].bounds);
    CGRect rect = [text boundingRectWithSize:CGSizeMake(max_width, CGRectGetHeight(self.bounds)-5) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:font]} context:nil];
    CGRect self_rect = self.bounds;
    self_rect.size.width = rect.size.width;
    self.bounds = self_rect;
}
@end
